<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="229px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="12">
					<el-form-item label="名称" prop="name"  >
						<el-input v-model="dataForm.name" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="法人" prop="fr"  >
						<el-input v-model="dataForm.fr" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="类型" prop="lx"  >
						<el-select v-model="dataForm.lx" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in lxOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="统一社会信用代码" prop="tyshxydm"  >
						<el-input v-model="dataForm.tyshxydm" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="纳税人识别号" prop="nsrsbm"  >
						<el-input v-model="dataForm.nsrsbm" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="组织机构代码" prop="zzjgdm"  >
						<el-input v-model="dataForm.zzjgdm" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="登记机关" prop="djjg"  >
						<el-input v-model="dataForm.djjg" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="成立日期" prop="clsj"  >
						<el-date-picker v-model="dataForm.clsj" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="注册地址" prop="zcdz"  >
						<el-input v-model="dataForm.zcdz" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":4}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="办公地址" prop="bgdz"  >
						<el-input v-model="dataForm.bgdz" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":4}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="供应资质证书" prop="gyzz" >
						<JNPF-UploadFz v-model="gyzzList" accept="" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</JNPF-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="供应资质名称" prop="gyzzmc"  >
						<el-input v-model="dataForm.gyzzmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="供应资质到期时间" prop="gyzzdqsj"  >
						<el-date-picker v-model="dataForm.gyzzdqsj" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="质量管理体系认证证书（ccc认证）" prop="zlgltxrzzs" >
						<JNPF-UploadFz v-model="zlgltxrzzsList" accept="" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</JNPF-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="生产、销售许可证" prop="xkz" >
						<JNPF-UploadFz v-model="xkzList" accept="" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</JNPF-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="产品质量合格证" prop="cpzlhgz" >
						<JNPF-UploadFz v-model="cpzlhgzList" accept="" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</JNPF-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="产品检验报告" prop="cpjybg" >
						<JNPF-UploadFz v-model="cpjybgList" accept="" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</JNPF-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="供应项目名称" prop="gyxmmc" >
						<el-input v-model="dataForm.gyxmmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="状态" prop="bz" >
						<el-select v-model="dataForm.bz" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ztOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					name:undefined,
					fr:undefined,
					lx:undefined,
					tyshxydm:undefined,
					nsrsbm:undefined,
					zzjgdm:undefined,
					djjg:undefined,
					clsj:undefined,
					zcdz:undefined,
					bgdz:undefined,
					gyzz:[],
					gyzzmc:undefined,
					gyzzdqsj:undefined,
					zlgltxrzzs:[],
					xkz:[],
					cpzlhgz:[],
					cpjybg:[],
					gyxmmc:undefined,
					bz:undefined,

        },
        rules: {
						name:[
						{
							required:true,
							message:'请输入名称',
							trigger:'blur'
						},
						],
						// fr:[
						// {
						// 	required:true,
						// 	message:'请输入法人',
						// 	trigger:'blur'
						// },
						// ],
						// lx:[
						// {
						// 	required:true,
						// 	message:'请输入类型',
						// 	trigger:'blur'
						// },
						// ],
						// tyshxydm:[
						// {
						// 	required:true,
						// 	message:'请输入统一社会信用代码',
						// 	trigger:'blur'
						// },
						// ],
						// nsrsbm:[
						// {
						// 	required:true,
						// 	message:'请输入纳税人识别号',
						// 	trigger:'blur'
						// },
						// ],
						// zzjgdm:[
						// {
						// 	required:true,
						// 	message:'请输入组织机构代码',
						// 	trigger:'blur'
						// },
						// ],
						// djjg:[
						// {
						// 	required:true,
						// 	message:'请输入登记机关',
						// 	trigger:'blur'
						// },
						// ],
						// clsj:[
						// {
						// 	required:true,
						// 	message:'请输入成立日期',
						// 	trigger:'blur'
						// },
						// ],
						// zcdz:[
						// {
						// 	required:true,
						// 	message:'请输入注册地址',
						// 	trigger:'blur'
						// },
						// ],
						// bgdz:[
						// {
						// 	required:true,
						// 	message:'请输入办公地址',
						// 	trigger:'blur'
						// },
						// ],
						// gyzzmc:[
						// {
						// 	required:true,
						// 	message:'请输入供应资质名称',
						// 	trigger:'blur'
						// },
						// ],
						gyzzdqsj:[
						{
							required:true,
							message:'请输入供应资质到期时间',
							trigger:'blur'
						},
						],
						// bz:[
						// {
						// 	required:true,
						// 	message:'请选择状态',
						// 	trigger:'blur'
						// },
						// ],

        },
				ztOptions:[{"fullName":"过期","id":"过期"},{"fullName":"正常","id":"正常"}],
				lxOptions:[{"fullName":"有限责任公司","id":"1"},{"fullName":"股份有限责任公司","id":"2"},{"fullName":"个人独资企业","id":"3"},{"fullName":"合伙企业","id":"4"},{"fullName":"个体工商户","id":"5"}],

					gyzzList:[],
					zlgltxrzzsList:[],
					xkzList:[],
					cpzlhgzList:[],
					cpjybgList:[],

      }
    },
    created() {

    },
    methods: {

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/wlgys/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;
				this.gyzzList = this.dataForm.gyzz ? JSON.parse(this.dataForm.gyzz) : [];
				this.zlgltxrzzsList = this.dataForm.zlgltxrzzs ? JSON.parse(this.dataForm.zlgltxrzzs) : [];
				this.xkzList = this.dataForm.xkz ? JSON.parse(this.dataForm.xkz) : [];
				this.cpzlhgzList = this.dataForm.cpzlhgz ? JSON.parse(this.dataForm.cpzlhgz) : [];
				this.cpjybgList = this.dataForm.cpjybg ? JSON.parse(this.dataForm.cpjybg) : [];

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
				this.$set(this.dataForm, 'gyzz', JSON.stringify(this.gyzzList));
				this.$set(this.dataForm, 'zlgltxrzzs', JSON.stringify(this.zlgltxrzzsList));
				this.$set(this.dataForm, 'xkz', JSON.stringify(this.xkzList));
				this.$set(this.dataForm, 'cpzlhgz', JSON.stringify(this.cpzlhgzList));
				this.$set(this.dataForm, 'cpjybg', JSON.stringify(this.cpjybgList));

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/wlgys',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/wlgys/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>